package com.wwtech.epp.ui.adapter.main;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.socks.library.KLog;
import com.wwtech.epp.R;
import com.wwtech.epp.db.Friend;
import com.wwtech.epp.view.GlideCircleTransform;

import java.util.List;

/**
 * Created by hu on 2017/9/13.
 */

public class GroupMemberCheckMangerAdapter extends BaseQuickAdapter<Friend, BaseViewHolder> {

    private boolean isCheckMode = false;
    private OnCheckChange onCheckChange;

    public boolean isCheckMode() {
        return isCheckMode;
    }

    public void setCheckMode(boolean checkMode) {
        isCheckMode = checkMode;
    }


    public GroupMemberCheckMangerAdapter(@Nullable List<Friend> data) {
        super(R.layout.item_contact_person, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Friend friend) {
        ImageView imageView = baseViewHolder.getView(R.id.avater);
        CheckBox checkBox = baseViewHolder.getView(R.id.check_box);
        if (isCheckMode) {
            checkBox.setVisibility(View.VISIBLE);
        } else {
            checkBox.setVisibility(View.GONE);
        }
        baseViewHolder.setOnCheckedChangeListener(R.id.check_box, new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (onCheckChange != null) {
                    onCheckChange.onCheckChange(friend, isChecked);
                }
            }
        });
        Glide.with(mContext)
                .load(friend.getAvatar())
                .transform(new GlideCircleTransform(mContext))
                .into(imageView);
        baseViewHolder.setText(R.id.name, friend.getNickname());
    }

    public interface OnCheckChange {
        void onCheckChange(Friend friend, boolean isChecked);
    }

    public void setOncheckChange(OnCheckChange oncheckChange) {
        this.onCheckChange = oncheckChange;
    }
}
